package com.ibm.commerce.url.tasks.cmc;

/**
 * Info 1
 * Info 2
 * Info 3
 * Info 4
 * Info 5
 * Info 6
 */

import com.ibm.commerce.url.harness.*;
import com.ibm.commerce.url.exception.*;
import com.ibm.wc.test.exception.DatablockMissingException;

import java.util.LinkedHashMap;
import java.util.Map;

public class CMCLogon extends URLTestTask {
	public static final String INPUT_PARAMETER_NAME_LOGONID = "logonId";
	public static final String INPUT_PARAMETER_NAME_LOGONPASSWORD = "logonPassword";
	
	private static CMCLogon instance = new CMCLogon();
	private CMCLogon(){}
	
	public static void execute() throws TaskFailException, DatablockMissingException {
		instance.runTask();
	}
	public static void execute(int counterIndex) throws TaskFailException, DatablockMissingException {
		instance.runTask(counterIndex);
	}
	
	private static Map<String, String> CMCLogonStep2_FORM = new LinkedHashMap<String, String>();
	static{
		CMCLogonStep2_FORM.put("XMLFile","common.mcLogon");
	}
	
	private static Map<String, String> CMCLogonStep3_FORM = new LinkedHashMap<String, String>();
	static{
		CMCLogonStep3_FORM.put("BrowserOk","true");
		CMCLogonStep3_FORM.put("XMLFile","common.mcLogon");
		CMCLogonStep3_FORM.put("slurl","StoreLanguageSelection");
		CMCLogonStep3_FORM.put("mcurl","MerchantCenterView?XMLFile=common.merchantCenter");
		CMCLogonStep3_FORM.put("reLogonURL","ToolsLogon?XMLFile=common.mcLogon");		
		CMCLogonStep3_FORM.put("URL","StoreLanguageSelection");
		CMCLogonStep3_FORM.put("logonId","");
		CMCLogonStep3_FORM.put("logonPassword","");
	}
	
	protected void executeTask() throws TaskFailException {
		CMCLogonStep1();
		CMCLogonStep2();
		CMCLogonStep3();
	}

	private void CMCLogonStep1() throws TaskFailException {
		
		WebHit("https://standardhost/accelerator", WEB_FORM_GET);

	}
	
	private void CMCLogonStep2() throws TaskFailException{
		// Add dynamically changed URL parameters begin
		// Add dynamically changed URL parameters end
		
		// Add global URL parameters begin
		// Add global URL parameters end
		
		// Main body start
		WebHit("https://standardhost/webapp/wcs/tools/servlet/Logon", WEB_FORM_POST, CMCLogonStep2_FORM);
		// Main body end
		
		// Save global URL parameters begin
		// Save global URL parameters end
	}
	
	private void CMCLogonStep3() throws TaskFailException{		
		// Add dynamically changed URL parameters begin
		putParameterInMap(CMCLogonStep3_FORM, "logonId", getParameterFromDataFile(INPUT_PARAMETER_NAME_LOGONID));
		putParameterInMap(CMCLogonStep3_FORM, "logonPassword", getParameterFromDataFile(INPUT_PARAMETER_NAME_LOGONPASSWORD));
		// Add dynamically changed URL parameters end
		
		// Add global URL parameters begin
		// putParameterInMap(CMCLogonStep3_FORM, "anotherParam", getParameterFromGlobalMap("logonPassword"));
		// Add global URL parameters end
		
		// Main body start
		WebHit("https://standardhost/webapp/wcs/tools/servlet/Logon", WEB_FORM_POST, CMCLogonStep3_FORM);
		// Main body end	
		
		// Save global URL parameters begin
		
		// Save global URL parameters end
		
		// Save task output parameters begin
		
		// Save task output parameters end
	}
	
}
